package com.itlong.cloud.resource;

import com.itlong.cloud.iottp.IIotTpJPushClientServiceClient;
import com.itlong.cloud.push.JPushClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * <desc>
 *      极光推送接口暴露。
 * <desc/>
 *
 * @createDate 2017/10/12.
 */
@RestController
public class IotTpJPushClientServiceResource implements IIotTpJPushClientServiceClient {

    @Autowired
    private JPushClientService jPushClientService;

    /**
     * <desc>
     *      推送所有平台，所有用户，内容为 msg 的通知。
     * <desc/>
     *
     * @param  msg  推送消息
     * @param  extra 附加字段
     * @return
     * @author shengen.T
     * @createDate 2017/10/12
     */
    @Override
    @RequestMapping(path = "/iotTp/push/pushAll")
    public boolean pushAll(@RequestParam("msg") String msg,@RequestBody Map<String,String> extra) {
        return jPushClientService.push(msg,extra);
    }

    /**
     * <desc>
     *      标签推送指令。
     * <desc/>
     *
     * @param   msg  推送消息
     * @param   projectId  项目编号
     * @param   userPhone  用户手机
     * @param   devSip  设备SIP
     * @param   roomSip 房间SIP
     * @return
     * @author shengen.T
     * @createDate 2017/10/12
     */
    @Override
    @RequestMapping(path = "/iotTp/push/pushWithTag")
    public boolean pushWithTag(@RequestParam("msg") String msg,
                               @RequestParam("projectId") String projectId,
                               @RequestParam("userPhone") String userPhone,
                               @RequestParam("devSip")String devSip,
                               @RequestParam("roomSip") String roomSip){
        return jPushClientService.pushWithTag(msg,projectId,userPhone,devSip,roomSip);
    }

    /**
     * <desc>
     *      任务指令推送。
     *      使用场景：APP账单详情
     * <desc/>
     *
     * @param userPhone  用户手机
     * @param serviceType  服务类型
     * @param msg
     * @return true 成功 false 失败
     * @author Jiaqi.X
     * @createDate 2018/08/20
     */
    @Override
    @RequestMapping(path = "/iotTp/push/pushWithTaskForBillTO")
    public boolean pushWithTaskForBillTO(@RequestParam("userPhone") String userPhone,
                                         @RequestParam("serviceType")String serviceType,
                                         @RequestParam("msg")String msg,
                                         @RequestParam("projectId")String projectId) throws IOException {
        return jPushClientService.pushWithTaskForBillTO(userPhone,serviceType,msg,projectId,null);
    }

    /**
     * <desc>
     *      云对讲强推送
     *      标签推送指令。
     * <desc/>
     *
     * @param   msg  推送消息
     * @param   userPhone  用户手机
     * @param   devSip  设备SIP
     * @param   roomSip 房间SIP
     * @return
     * @author shengen.T
     * @createDate 2017/10/12
     */
    @Override
    @RequestMapping(path = "/iotTp/push/pushWithByPhoneTag",method = RequestMethod.POST)
    public boolean pushWithByPhoneTag(@RequestParam("msg") String msg,
                                      @RequestParam("userPhone") String userPhone,
                                      @RequestParam("devSip")String devSip,
                                      @RequestParam("roomSip") String roomSip) throws Exception{
        return jPushClientService.pushWithTag(msg,userPhone,devSip,roomSip);
    }

    /**
     * <desc>
     *      标签推送指令。
     * <desc/>
     *
     * @param   msg  推送消息
     * @param   projectId  项目编号
     * @return
     * @author shengen.T
     * @createDate 2017/10/12
     */
    @Override
    @RequestMapping(path = "/iotTp/push/pushWithProjectTag")
    public boolean pushWithProjectTag(@RequestParam("msg") String msg,
                               @RequestParam("projectId") String projectId){
        return jPushClientService.pushWithProjectTag(msg,projectId);
    }

    /**
     * <desc>
     *      任务指令推送。
     * <desc/>
     *
     * @param  projectId 项目编号
     * @param   userPhone  用户手机
     * @param  comands 指令
     * @param  msg 推送信息
     * @return
     * @author shengen.T
     * @createDate 2017/10/12
     */

    @Override
    @RequestMapping(path = "/iotTp/push/pushWithTaskTO")
    public boolean pushWithTaskTO(@RequestParam("projectId") String projectId,
                          @RequestParam("userPhone") String userPhone,
                         @RequestBody Map<String,String> comands,
                         @RequestParam("msg") String msg) throws Exception{
        return jPushClientService.pushWithTaskTO(projectId,userPhone,comands,msg);
    }


    /**
     * <desc>
     *      任务指令推送。
     * <desc/>
     *
     * @param   userPhone  用户手机
     * @param  comands 指令
     * @param  msg 推送信息
     * @return
     * @author shengen.T
     * @createDate 2017/10/12
     */
    @Override
    @RequestMapping(path = "/iotTp/push/pushWithTask")
    public boolean pushWithTask(@RequestParam("userPhone") String userPhone,
                         @RequestBody Map<String,String> comands,
                         @RequestParam("msg") String msg){
        return jPushClientService.pushWithTask(userPhone,comands,msg);
    }

    /**
     * <desc>
     *      别名指令推送。
     * <desc/>
     *
     * @param  msg 推送信息
     * @param  alias 别名列表
     * @return
     * @author shengen.T
     * @createDate 2017/10/12
     */
    @Override
    @RequestMapping(path = "/iotTp/push/pushWithAliases")
    public boolean pushWithAliases (@RequestParam("alias") List<String> alias, @RequestParam("msg") String msg){
        return jPushClientService.pushWithAliases(alias,msg);
    }

    /**
     * <desc>
     *      任务指令推送。
     *      重复登录提示
     * <desc/>
     *
     * @param   phoneNO  用户手机
     * @param  uuid 唯一编号
     * @param  msg 推送信息
     * @return
     * @author shengen.T
     * @createDate 2017/10/12
     */
    @Override
    @RequestMapping(path = "/iotTp/push/pushWithTaskLogin",method = RequestMethod.POST)
    public boolean pushWithTaskLogin(@RequestParam("phoneNO") String phoneNO,
                                @RequestParam("uuid") String uuid,
                                @RequestParam("msg") String msg) throws Exception{
        return jPushClientService.pushWithTaskTOLogin(phoneNO,uuid,msg);
    }

    /**
     * <desc>
     *      人脸认证消息推送。
     * <desc/>
     *
     * @param   userPhone  用户手机
     * @param  comands 指令
     * @param  msg 推送信息
     * @return
     * @author shengen.T
     * @createDate 2018-05-08
     */
    @Override
    @RequestMapping(path = "/iotTp/push/pushWithFaceVerificationTask",method = RequestMethod.POST)
    public boolean pushWithFaceVerificationTask(@RequestParam("userPhone") String userPhone,
                                         @RequestParam("msg") String msg,
                                         @RequestBody Map<String,String> comands) throws Exception{
        return jPushClientService.pushWithFaceVerificationTask(userPhone,msg,comands);
    }

}
